package com.yangoxix.lovegoing.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yangoxix.lovegoing.pojo.Activity;
import com.yangoxix.lovegoing.pojo.ActivityPageQuery;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ActiticyMapper extends BaseMapper<Activity> {
    @Select("select activity.activityname                               as name,\n" +
            "       (IF(length(detail) > 25, left(detail, 25), detail)) as detail,\n" +
            "       group_concat(imgurl)                                as urls\n" +
            "from activity\n" +
            "         left join img i\n" +
            "                   on activity.activityname = i.activityname\n" +
            "group by activity.activityname")
    List<ActivityPageQuery> selectAllActivityPages();

    @Select("select activity.activityname                               as name,\n" +
            "       (IF(length(detail) > 25, left(detail, 25), detail)) as detail,\n" +
            "       group_concat(imgurl)                                as urls\n" +
            "from activity\n" +
            "         left join img i\n" +
            "                   on activity.activityname = i.activityname\n" +
            "where " +
            "activity.activityname in (\n" +
            "    select useractivity.activityname\n" +
            "    from useractivity\n" +
            "    where username = #{username}\n" +
            ")\n" +
            "group by activity.activityname")
    List<ActivityPageQuery> selectActivityPagesViaUsername(@Param("username") String username);
}
